import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
import React, { Component } from 'react';
import { object, func, string } from 'prop-types';

import Button from 'antd/lib/button';
import Modal from 'antd/lib/modal';
import { noop } from '../../libs/utils';

var ErrorModal = function (_Component) {
  _inherits(ErrorModal, _Component);

  function ErrorModal() {
    var _temp, _this, _ret;

    _classCallCheck(this, ErrorModal);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.state = {
      show: false
    }, _this.onClose = function () {
      _this.setState({
        show: false
      });

      _this.modal.box.addEventListener('transitionend', function () {
        _this.props.onClose();
      });
    }, _this.bindModalRef = function (ref) {
      _this.modal = ref;
    }, _temp), _possibleConstructorReturn(_this, _ret);
  }

  ErrorModal.prototype.componentDidMount = function componentDidMount() {
    var _this2 = this;

    this.animationFrame = requestAnimationFrame(function () {
      _this2.setState({
        show: true
      });
    });
  };

  ErrorModal.prototype.componentWillUnmount = function componentWillUnmount() {
    cancelAnimationFrame(this.animationFrame);
  };

  ErrorModal.prototype.render = function render() {
    var error = this.props.error;
    var show = this.state.show;

    var errMsg = error;

    return React.createElement(
      Modal,
      {
        ref: this.bindModalRef,
        title: 'Error',
        onClose: this.onClose,
        shown: show
      },
      React.createElement('div', {
        className: 'modal-body',
        dangerouslySetInnerHTML: { __html: '' + errMsg } // eslint-disable-line
      }),
      React.createElement(
        'div',
        { className: 'modal-footer' },
        React.createElement(
          Button,
          { type: 'secondary', onClick: this.onClose, noSubmit: true },
          'Close'
        )
      )
    );
  };

  return ErrorModal;
}(Component);

ErrorModal.propTypes = {
  onClose: func,
  error: string
};
ErrorModal.defaultProps = {
  onClose: noop,
  error: 'string'
};
export default ErrorModal;